package com.example.myapplication.dao;

import android.os.Handler;
import android.os.Message;
import android.widget.Toast;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;


public class HttpDao {

    public static String urladd = "http://192.168.6.189:8080/";
    public boolean isConn = false;

    public HttpDao(Handler handler) {
        new Thread(() -> {
            try {
                HttpURLConnection conn;
                URL url = new URL(HttpDao.urladd);
                conn = (HttpURLConnection) url.openConnection();
                conn.setConnectTimeout(1000 * 5);
                Message message = handler.obtainMessage();
                if (conn.getResponseCode() == 200) {
                    isConn = true;

                    message.what = 4;
                    message.arg1 = 1;

                }
                else message.arg1 = 0;
                handler.sendMessage(message);
                conn.disconnect();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }).start();

    }
}
